package com.whz.enumdemo;

import java.util.Optional;

/**
 * @Author: sinosoft
 * @Description:
 * @Date: Create in 18:03 2021/5/13
 * @Modified By:
 */
public class OperationMainTest {
    public static void main(String[] args) {
        double x = 100d;
        double y = 2d;
        for(Operation op : Operation.values()) {
            System.out.printf("%f %s %f = %f%n", x, op, y, op.apply(x, y));
        }
        /*
         * enum类型中自带方法 valueOf(常量的名字)
         * 它将常量的名字转变成常量本身
         * */
        Operation operation = Operation.valueOf("PLUS");

        System.out.println(operation == Operation.PLUS);

        Optional<Operation> optional = Operation.fromString("+");

        System.out.printf("测试fromString : %s%n", Operation.PLUS == optional.get());

        Operation inverse = Operation.inverse(Operation.PLUS);

        System.out.printf("inverse: %s%n", inverse);


    }
}
